<!-- index.html -->
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>服务器后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/styles.css">
</head>
<body>
<!-- 顶部导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">服务器后台管理</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item"><a class="nav-link" href="#" onclick="loadPage('base')">基础功能</a></li>
                <li class="nav-item"><a class="nav-link" href="#" onclick="loadPage('account')">账号管理</a></li>
                <li class="nav-item"><a class="nav-link" href="#" onclick="loadPage('status')">在线状态</a></li>
                <li class="nav-item"><a class="nav-link" href="#" onclick="loadPage('call')">通话记录</a></li>
                <li class="nav-item"><a class="nav-link" href="#" onclick="loadPage('reserve')">保留账号</a></li>
                <li class="nav-item"><a class="nav-link" href="#" onclick="loadPage('admin')">后台用户</a></li>
            </ul>
        </div>
    </div>
</nav>

<!-- 主要内容 -->
<div class="container my-4" id="content">
    <!-- 动态加载的内容 -->
</div>

<!-- 全局弹窗 -->
<div id="global-toast" class="toast align-items-center text-bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
    <div class="d-flex">
        <div class="toast-body" id="toast-message"></div>
    </div>
</div>

<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/script.js"></script>
<script>
    let currentScript = null; // 当前加载的 JS 文件

    function loadPage(page) {
        // 清除之前加载的 JS 文件
        if (currentScript) {
            document.head.removeChild(currentScript);
            currentScript = null;
        }

        // 加载 HTML 内容
        fetch(`${page}.html`)
            .then(response => response.text())
            .then(html => {
                document.getElementById('content').innerHTML = html;

                // 动态加载对应的 JS 文件
                const script = document.createElement('script');
                script.src = `js/${page}.js`;
                script.onload = () => {
                    currentScript = script; // 记录当前加载的 JS 文件
                };
                document.head.appendChild(script);
            })
            .catch(error => console.error('Error loading page:', error));
    }

    window.onload = () => loadPage('base');
</script>
</body>
</html>